﻿CREATE PROCEDURE [dbo].[usp_select_Faults_By_Application_And_ErrorType]
(
        @Application		varchar(255)	= NULL
	   ,@ErrorType		varchar(255)	= NULL
	   ,@StartDate			datetime		= NULL
	   ,@EndDate			datetime		= NULL
)
AS

SET NOCOUNT ON;

SET @EndDate = DATEADD(day,1,@EndDate)

select 
  Fault.*
from dbo.Fault
where 
	[Application] IN(SELECT [Application] FROM [udf_SplitApplications](@Application))
	and [ErrorType] = @ErrorType
	and [DateTime] between @StartDate and @EndDate
order by [Application], [ServiceName], [ErrorType]


SET NOCOUNT OFF;
